/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package system;

import java.util.ArrayList;
import sql.SQLHandler;
/**
 *
 * @author Micke
 */
public class UserHandler {

    User currentUser;
    ArrayList<User> users;
    
    GradeHandler gh;
    SQLHandler sql;

    public UserHandler(SQLHandler sql) {
        this.sql = sql;
        

        users = new ArrayList<User>();
        getUsers();
        
        //gh=new GradeHandler(sql);
        

    }

    public void getUsers() {
        users=sql.getUsers();
    }

    public String getCurrentUserName(){
        return currentUser.getUserName();
    }


    public User getCurrentUser() {
        return currentUser;
    }

    public boolean login(String userName, String password) {
        if(!sql.isConnected()){
            sql.Connect();
        }
        for (int i = 0; i < users.size(); i++) {
            if (users.get(i).getUserName().equals(userName) && users.get(i).getPassword().equals(password)) {
                currentUser = new User(users.get(i).getUserName(), users.get(i).getUserID(), users.get(i).getPassword());
                return true;
            }
        }

        return false;
    }
}
